{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "CreateUCISyntheticDataset.ipynb",
      "provenance": [
        {
          "file_id": "1EYOGQiordiZp7CQMm8UJl33_tH9iB8rN",
          "timestamp": 1579567890036
        }
      ],
      "collapsed_sections": [],
      "last_runtime": {
        "build_target": "//research/colab/notebook:notebook_backend_py3",
        "kind": "private"
      }
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1erVaCIS4bmi",
        "colab_type": "text"
      },
      "source": [
        "**Copyright 2020 Google LLC.**\n",
        "\n",
        "Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n",
        "\n",
        "https://www.apache.org/licenses/LICENSE-2.0\n",
        "\n",
        "Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Ynmlap5aip_f",
        "colab_type": "text"
      },
      "source": [
        "## Overview\n",
        "\n",
        "### Generate synthetic datasets for various settings by sampling the original UCI_Adult dataset:\n",
        "\n",
        "Pre-requisite: Download the Adult train and test data files can be downloaded from: https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.test and save them in the ./group_agnostic_fairness/data/uci_adult folder.\n",
        "\n",
        "This notebook contains code to create synthetic datasets over the original uci_adult dataset. We provide code to control various parameters like \"base-rate\", \"group-size\", and \"label-noise\" and generate synthetic dataset by over-sampling / under-samping original uci_adult training dataset."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oQXx_KOalSTH",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from __future__ import division\n",
        "import pandas as pd\n",
        "import numpy as np\n",
        "import json\n",
        "import collections\n",
        "import os\n",
        "import seaborn as sns\n",
        "import matplotlib.pyplot as plt"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "d6xEXeTP4ztd",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "sns.set_context('paper',font_scale=1.5)\n",
        "dataset_base_dir = './group_agnostic_fairness/data/uci_adult/'"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "foh3NoCAx3Kn",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "def sample_data(data_df, num=None, restrictions=None):\n",
        "  \"\"\"A recursive function that samples data according to the restrictions.\n",
        "\n",
        "  Sampling is done with replacement.\n",
        "\n",
        "  The restrictions determine how the data should be sampled.\n",
        "\n",
        "  For example, \n",
        "  column_types = ['sex:Female','income:>50K']\n",
        "  percentages =  [[0.33,0.6]]\n",
        "  Returns an object of type Restriction, which can be used to sample a dataset \n",
        "  in which fraction of females is 0.33, and female-base-rate (females with income >50k) is 0.66. \n",
        "  Data for non-female group is sampled uniformly at random, \n",
        "  hence will have similar base-rate as in the original distribution.\n",
        "\n",
        "  Args:\n",
        "    data_df: A pandas DataFrame containing the dataset that should be sampled.\n",
        "    num: The total number of samples needed.\n",
        "    restrictions: A list of restrictions. Each restriction contains a column\n",
        "      name, a list of types (a value for a bucket), and a list of percentages.\n",
        "  Returns:\n",
        "    A pandas DataFrame of size 'num' that holds up to each of the restrictions.\n",
        "  \"\"\"\n",
        "  if not num:\n",
        "    num = data_df.shape[0]\n",
        "  if not restrictions:\n",
        "    return data_df.sample(n=num,replace=True)\n",
        "  num_other = num\n",
        "  other_subset = np.full(data_df.shape[0], True)\n",
        "  subsamples = []\n",
        "  for tp, percent in zip(restrictions[0].types, restrictions[0].percentages):\n",
        "    subset = data_df[restrictions[0].column_name] == tp\n",
        "    num_samples = (int)(num * percent)\n",
        "    subsamples.append(\n",
        "        sample_data(data_df[subset], num_samples, restrictions[1:]))\n",
        "    num_other -= num_samples\n",
        "    other_subset = other_subset & (-subset)\n",
        "  if num_other > 0:\n",
        "    subsamples.append(\n",
        "        sample_data(data_df[other_subset], num_other, restrictions=None))\n",
        "  \n",
        "  # Concat and shuffle\n",
        "  sample_df = pd.concat(subsamples, ignore_index=True).sample(frac=1.0)\n",
        "  return sample_df"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "K4BIuy9Wvo_y",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "def sample_data_and_flip_class_label(data_df, frac, flip_dict):\n",
        "  \"\"\" Samples specified fraction of samples and flips their class label.\n",
        "    flip_dict: A dictionary of the form {current_value:new_value}.\n",
        "      Example {'<=50K':'>50K','>50K':'<=50K'}\n",
        "  Returns:\n",
        "    A pandas DataFrame with specified fraction of column values flipped\n",
        "  \"\"\"\n",
        "  flip_df = data_df.sample(frac=frac)\n",
        "  flip_df.replace(to_replace=flip_dict,inplace=True)\n",
        "  keep_df = data_df.drop(flip_df.index).sample(frac=1.0)\n",
        "  # Concat and shuffle\n",
        "  sample_df = pd.concat([keep_df,flip_df]).sample(frac=1.0)\n",
        "  return sample_df"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "yEYdy2adyWrt",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "Restriction = collections.namedtuple(\n",
        "    'Restriction', ['column_name', 'types', 'percentages'])\n",
        "\n",
        "def create_restrictions(column_types, percentages):\n",
        "  \"\"\"Creates a list of restrictions.\n",
        "\n",
        "  For example, \n",
        "  column_types = ['sex:Female','income:>50K']\n",
        "  percentages =  [[0.33,0.6]]\n",
        "  Returns an object of type Restriction, which can be used to sample a dataset \n",
        "  in which fraction of females is 0.33, and female-base-rate (females with income >50k) is 0.66. \n",
        "  Data for non-female group is sampled uniformly at random, hence will have similar base-rate as in the original distribution.\n",
        "\n",
        "  Args:\n",
        "    column_types: A list of column type strings. They must be of the form\n",
        "      '(column name):(type name)'.\n",
        "    percentages: A list of percentages for each column type.\n",
        "  Returns:\n",
        "    A list of restrictions\n",
        "  \"\"\"\n",
        "  # Parse through the lists and create columns. We can have multiple types for\n",
        "  # one column name.\n",
        "  restrictions_dict = collections.defaultdict(list)\n",
        "  percentages_dict = collections.defaultdict(list)\n",
        "  if column_types and percentages:\n",
        "    for column_type, percentage in zip(column_types, percentages):\n",
        "      column, tp = column_type.split(':')\n",
        "      restrictions_dict[column].append(tp)\n",
        "      percentages_dict[column].append(percentage)\n",
        "  # Now create the restrictions.\n",
        "  restrictions = []\n",
        "  for k in restrictions_dict:\n",
        "    restrictions.append(\n",
        "        Restriction(k, restrictions_dict[k], percentages_dict[k]))\n",
        "  return restrictions"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "AqX6EQ96mBAo",
        "colab_type": "text"
      },
      "source": [
        "## Load Training Dataset"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oA1tezgRlVXT",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "TRAIN_FILE = os.path.join(dataset_base_dir,'adult.data')\n",
        "feature_names = [\n",
        "    \"age\", \"workclass\", \"fnlwgt\", \"education\", \"education-num\",\n",
        "    \"marital-status\", \"occupation\", \"relationship\", \"race\", \"sex\",\n",
        "    \"capital-gain\", \"capital-loss\", \"hours-per-week\", \"native-country\", \"income\"\n",
        "]\n",
        "\n",
        "with open(TRAIN_FILE, \"r\") as TRAIN_FILE:\n",
        "  train_df = pd.read_csv(TRAIN_FILE,sep=',',names=feature_names)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-jGuNakm1hnU",
        "colab_type": "code",
        "outputId": "208b8638-2ed1-45a1-f0c1-d78d290800de",
        "executionInfo": {
          "status": "ok",
          "timestamp": 1579569038496,
          "user_tz": 480,
          "elapsed": 338,
          "user": {
            "displayName": "Preethi Lahoti",
            "photoUrl": "",
            "userId": "13345756409883217889"
          }
        },
        "colab": {
          "height": 204
        }
      },
      "source": [
        "train_df.head()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>age</th>\n",
              "      <th>workclass</th>\n",
              "      <th>fnlwgt</th>\n",
              "      <th>education</th>\n",
              "      <th>education-num</th>\n",
              "      <th>marital-status</th>\n",
              "      <th>occupation</th>\n",
              "      <th>relationship</th>\n",
              "      <th>race</th>\n",
              "      <th>sex</th>\n",
              "      <th>capital-gain</th>\n",
              "      <th>capital-loss</th>\n",
              "      <th>hours-per-week</th>\n",
              "      <th>native-country</th>\n",
              "      <th>income</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>39</td>\n",
              "      <td>State-gov</td>\n",
              "      <td>77516</td>\n",
              "      <td>Bachelors</td>\n",
              "      <td>13</td>\n",
              "      <td>Never-married</td>\n",
              "      <td>Adm-clerical</td>\n",
              "      <td>Not-in-family</td>\n",
              "      <td>White</td>\n",
              "      <td>Male</td>\n",
              "      <td>2174</td>\n",
              "      <td>0</td>\n",
              "      <td>40</td>\n",
              "      <td>United-States</td>\n",
              "      <td>&lt;=50K</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>50</td>\n",
              "      <td>Self-emp-not-inc</td>\n",
              "      <td>83311</td>\n",
              "      <td>Bachelors</td>\n",
              "      <td>13</td>\n",
              "      <td>Married-civ-spouse</td>\n",
              "      <td>Exec-managerial</td>\n",
              "      <td>Husband</td>\n",
              "      <td>White</td>\n",
              "      <td>Male</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>13</td>\n",
              "      <td>United-States</td>\n",
              "      <td>&lt;=50K</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>38</td>\n",
              "      <td>Private</td>\n",
              "      <td>215646</td>\n",
              "      <td>HS-grad</td>\n",
              "      <td>9</td>\n",
              "      <td>Divorced</td>\n",
              "      <td>Handlers-cleaners</td>\n",
              "      <td>Not-in-family</td>\n",
              "      <td>White</td>\n",
              "      <td>Male</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>40</td>\n",
              "      <td>United-States</td>\n",
              "      <td>&lt;=50K</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>53</td>\n",
              "      <td>Private</td>\n",
              "      <td>234721</td>\n",
              "      <td>11th</td>\n",
              "      <td>7</td>\n",
              "      <td>Married-civ-spouse</td>\n",
              "      <td>Handlers-cleaners</td>\n",
              "      <td>Husband</td>\n",
              "      <td>Black</td>\n",
              "      <td>Male</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>40</td>\n",
              "      <td>United-States</td>\n",
              "      <td>&lt;=50K</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>28</td>\n",
              "      <td>Private</td>\n",
              "      <td>338409</td>\n",
              "      <td>Bachelors</td>\n",
              "      <td>13</td>\n",
              "      <td>Married-civ-spouse</td>\n",
              "      <td>Prof-specialty</td>\n",
              "      <td>Wife</td>\n",
              "      <td>Black</td>\n",
              "      <td>Female</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>40</td>\n",
              "      <td>Cuba</td>\n",
              "      <td>&lt;=50K</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   age         workclass  fnlwgt  ... hours-per-week  native-country income\n",
              "0   39         State-gov   77516  ...             40   United-States  <=50K\n",
              "1   50  Self-emp-not-inc   83311  ...             13   United-States  <=50K\n",
              "2   38           Private  215646  ...             40   United-States  <=50K\n",
              "3   53           Private  234721  ...             40   United-States  <=50K\n",
              "4   28           Private  338409  ...             40            Cuba  <=50K\n",
              "\n",
              "[5 rows x 15 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 14
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "pUlJmY8fqkam"
      },
      "source": [
        "## Sample data to have a specified group-size: Testing if the data is sampled as expected:"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "S_FEpomKqka2"
      },
      "source": [
        "#### Original data distribution"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "outputId": "2d9e1d69-5a55-4b3f-b482-6fde2bbd455d",
        "executionInfo": {
          "status": "ok",
          "timestamp": 1579569910907,
          "user_tz": 480,
          "elapsed": 367,
          "user": {
            "displayName": "Preethi Lahoti",
            "photoUrl": "",
            "userId": "13345756409883217889"
          }
        },
        "id": "FZ7DoqAfqkas",
        "colab": {
          "height": 85
        }
      },
      "source": [
        "print('Female group-size in original train-data: {}'.format(len(train_df[(train_df.sex=='Female')])/len(train_df)))\n",
        "print('Male group-size  in original data: {}'.format(len(train_df[(train_df.sex!='Female')])/len(train_df)))\n",
        "print('Female base-rate in original train-data: {}'.format(len(train_df[(train_df.sex=='Female') & (train_df.income == '>50K')])/len(train_df[(train_df.sex=='Female')])))\n",
        "print('Male base-rate in original data: {}'.format(len(train_df[(train_df.sex!='Female') & (train_df.income == '>50K')])/len(train_df[(train_df.sex!='Female')])))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Female group-size in original train-data: 0.33079450876815825\n",
            "Male group-size  in original data: 0.6692054912318418\n",
            "Female base-rate in original train-data: 0.10946058861758426\n",
            "Male base-rate in original data: 0.3057365764111978\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "outputId": "7d86eef6-3d35-410e-b7cb-3a6ab0ebf56d",
        "executionInfo": {
          "status": "ok",
          "timestamp": 1579569912460,
          "user_tz": 480,
          "elapsed": 583,
          "user": {
            "displayName": "Preethi Lahoti",
            "photoUrl": "",
            "userId": "13345756409883217889"
          }
        },
        "id": "7oSLYrlWqka3",
        "colab": {
          "height": 218
        }
      },
      "source": [
        "sns.catplot(data=train_df,x='income',hue='sex',kind='count',size=3)\n",
        "plt.show()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAASQAAADJCAYAAACKVE8EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAH+lJREFUeJzt3XtUVFX/P/D3gNxvCjKgqFwNHjBR\nMFBRbiMSQkup9FFTREwuTngB74w1UN7SxzS8ZYlQovHQg8mDUV5AtKyBIC9oy8sT5F1Q1BagBMz+\n/eGP83UEdFCGOTif11pnxZy9Z8/es/K99jlzzj4CxhgDIYTwgJa6O0AIIS0okAghvEGBRAjhDQok\nQghvUCARQniDAokQwhsUSIQQ3qBAIoTwBgUSIYQ3KJAIIbxBgdQBAoFA3V0g5KVGgUQI4Q0KJEII\nb1AgEUJ4o0sDKScnByKRCGZmZq3Oxxw9ehQCgUBhGzJkiEKd2tpaREZGwtTUFBYWFkhMTERzc7NC\nnV27dsHe3h4GBgYICAjApUuXFMovXLgAf39/GBgYwN7eHunp6SoZKyGk47o0kOrr6xEYGIilS5e2\nW+fGjRvcduTIEYUysViMkpISHD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3HgwAF8//33OHnyJBYuXMiVHz58GMHBwfD09MTP\nP/8MmUyGiIgINDY2AgC2bt2KFStWYOnSpTh79iwWLVqEpUuXYufOnQqfk5qaioEDB6K0tBRz587F\n3LlzER4eDnt7e5SUlOC9997D3Llzce7cOQCPgu6NN97AqVOnkJWVhfLycsTFxWHy5Mm0XAhpm/pu\noyPPa8aMGUwkEnF/9+7dW+Hm1NWrVzNra2vu9ahRo1hoaGi77fXr148tWrRIYd/8+fOZvb0999rW\n1paNHz+ee93c3MxMTExYWFiYwr6ePXuy1NRUxhhjhYWFTE9Pj927d0+h7ZkzZyq0RUgLmiG9BP7x\nj39AT0+Pe21jY4Nbt25xr0tLSzF27Ng23/vXX3/h6tWr8PX1Vdjv5+eHyspK1NfXc/vc3d25v7W0\ntLg1sR/fJxQKucXVSkpK8Pfff8PGxkZhAbrdu3e3+wQRotloVfSXwJOP/REIBGBP/Fbx+IL5bXmy\n/Mn3A2j1RA+BQNDmvpZF/eVyOczMzFBSUvLMPhMC0DkkjeDp6YkffvihzTJTU1P069cPRUVFCvuP\nHTsGe3t7hccTddSwYcNw7949PHz4EE5OTgrbgAEDnrtd8vKiGZIGWLFiBUJCQjB//nxERUVBT08P\nP//8M0aMGAFnZ2csW7YMiYmJGDhwIPz9/VFQUIBt27Zhy5YtL/S5gYGBGDNmDN58802sXbsW7u7u\nuHv3Lk6cOAF9fX3Mnj27k0ZIXhYUSBpg7Nix+O677yCVSvHZZ59BV1cXHh4e3HmjuLg41NXVYdWq\nVZgzZw769++PNWvWYNasWS/0uQKBALm5uUhOTkZCQgKuXbsGc3NzDBkyBIsXL+6MoZGXDF0YSQjh\nDTqHRAjhDQokQghvUCARQniDAokQwhsUSIQQ3qBAIoTwBgUSIYQ3KJAIIbzx/wAGhSYGiuMWSAAA\nAABJRU5ErkJggg==\n",
            "text/plain": [
              "<Figure size 432.984x300 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "KAHLyF0eqka5"
      },
      "source": [
        "#### Synthetic data distribution"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "outputId": "0ec76dc8-6468-45c3-b3e7-9d416f62e00b",
        "executionInfo": {
          "status": "ok",
          "timestamp": 1579569914533,
          "user_tz": 480,
          "elapsed": 382,
          "user": {
            "displayName": "Preethi Lahoti",
            "photoUrl": "",
            "userId": "13345756409883217889"
          }
        },
        "id": "TxDRJe-pqkaw",
        "colab": {
          "height": 34
        }
      },
      "source": [
        "column_types = ['sex:Female']\n",
        "percentages = [0.4]\n",
        "restrictions = create_restrictions(column_types,percentages)\n",
        "print('Sampling data with restrictions: {}'.format(restrictions))\n",
        "sampled_train_df = sample_data(train_df, restrictions=restrictions)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Sampling data with restrictions: [Restriction(column_name='sex', types=['Female'], percentages=[0.4])]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "outputId": "3b6254b6-1605-4006-8d85-824b06e3f83f",
        "executionInfo": {
          "status": "ok",
          "timestamp": 1579569915235,
          "user_tz": 480,
          "elapsed": 358,
          "user": {
            "displayName": "Preethi Lahoti",
            "photoUrl": "",
            "userId": "13345756409883217889"
          }
        },
        "id": "kN7c1CKqqka0",
        "colab": {
          "height": 85
        }
      },
      "source": [
        "# Base-rate remains similar as in original distribution, group-size changes\n",
        "print('Female group-size in synthetic data: {}'.format(len(sampled_train_df[(sampled_train_df.sex=='Female')])/len(sampled_train_df)))\n",
        "print('Male group-size in synthetic data: {}'.format(len(sampled_train_df[(sampled_train_df.sex!='Female')])/len(sampled_train_df)))\n",
        "print('Female base-rate in synthetic data: {}'.format(len(sampled_train_df[(sampled_train_df.sex=='Female') & (sampled_train_df.income == '>50K')])/len(sampled_train_df[(sampled_train_df.sex=='Female')])))\n",
        "print('Male base-rate in synthetic data: {}'.format(len(sampled_train_df[(sampled_train_df.sex!='Female') & (sampled_train_df.income == '>50K')])/len(sampled_train_df[(sampled_train_df.sex!='Female')])))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Female group-size in synthetic data: 0.3999877153650072\n",
            "Male group-size in synthetic data: 0.6000122846349928\n",
            "Female base-rate in synthetic data: 0.10910626535626536\n",
            "Male base-rate in synthetic data: 0.3041920458616983\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "outputId": "3b6fb408-6b33-4f97-dab6-cd87c947caa8",
        "executionInfo": {
          "status": "ok",
          "timestamp": 1579569928511,
          "user_tz": 480,
          "elapsed": 621,
          "user": {
            "displayName": "Preethi Lahoti",
            "photoUrl": "",
            "userId": "13345756409883217889"
          }
        },
        "id": "JiylceYXqka6",
        "colab": {
          "height": 218
        }
      },
      "source": [
        "# Group sizes changes, base-rate remain the same.\n",
        "sns.catplot(data=sampled_train_df,x='income',hue='sex',hue_order=['Male','Female'],order=['<=50K','>50K'],kind='count',size=3)\n",
        "plt.show()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAASQAAADJCAYAAACKVE8EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAHKhJREFUeJzt3XlUFFf+NvCnUfZNURZFw6bBUaNR\nFFxZbNEYyVGS6KhxQaKAdnBBcQMTcOIWHUclSmIyqImYMDqYcDQkasAtmgY1oqDHZQaMO7hmBMVg\n3/cPf9RrC2ij3VDYz+ecOoeuW139vSQ83qquuqUQQggQEcmASX0XQERUiYFERLLBQCIi2WAgEZFs\nMJCISDYYSEQkGwwkIpINBhIRy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PP/0U5eXliI6O\nRtOmTeHq6opPP/1U6313797F1KlT4erqCisrK3Tp0gXp6ekG/O1QQ8ZAegnk5uYiOzsbO3bswI8/\n/ohjx45h5syZUvvu3bsxcOBA+Pj44NChQ1Cr1Rg7diz+/PNPAMDatWsxf/58zJkzBwUFBYiNjcWc\nOXPwz3/+U+tzkpKS0LZtWxw5cgRTpkzBlClTEBoaCg8PD+Tm5uKDDz7AlClTcPLkSQCPgu6tt95C\nXl4e0tLSkJ+fj0mTJmHEiBGcLoSqV3+30dHzGjdunFAqldLPzZs317o5dfHixcLFxUV63adPHzF4\n8OAa99eqVSsRGxurtW7atGnCw8NDeu3m5iaGDBkivX748KGwtbUVISEhWuuaNGkikpKShBBCZGdn\nC3Nzc3H79m2tfY8fP15rX0SVOEJ6CfzlL3+Bubm59NrV1RXXrl2TXh85cgQDBgyo9r1//PEHLl68\nCH9/f631AQEBKCoqQllZmbSuc+fO0s8mJibSnNiPr3NycpImV8vNzcWDBw/g6uqqNQHdpk2banyC\nCBk3zor+EnjysT8KhQLiie8qHp8wvzpPtj/5fgBVnuihUCiqXVc5qb9Go4G9vT1yc3OfWTMRwHNI\nRsHHxwc//fRTtW12dnZo1aoV9u7dq7V+37598PDw0Ho8UW1169YNt2/fxv3799GmTRut5ZVXXnnu\n/dLLiyMkIzB//nwMGjQI06ZNQ3h4OMzNzXHo0CH07NkT3t7emDt3LmbMmIG2bdsiMDAQWVlZSE5O\nxpo1a17oc/v164f+/fvj7bffxtKlS9G5c2fcunULBw8ehIWFBSZOnKinHtLLgoFkBAYMGIAffvgB\nCQkJ+Pzzz2FmZoauXbtK540mTZqE0tJSLFq0CJMnT0br1q2xZMkSvP/++y/0uQqFAhkZGUhMTERM\nTAwuXboEBwcHvP7665g1a5Y+ukYvGV4YSUSywXNIRCQbDCQikg0GEhHJBgOJiGSDgUREssFAIiLZ\nYCARkWwwkIhINv4fuY+NcaGaKlUAAAAASUVORK5CYII=\n",
            "text/plain": [
              "<Figure size 432.984x300 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "D2ttHNbMks2_",
        "colab_type": "text"
      },
      "source": [
        "## Sample data to have a specified group base-rate: Testing if the data is sampled as expected:"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "om2IYVW8qD84",
        "colab_type": "text"
      },
      "source": [
        "#### Original data distribution"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "huNVldIfjbUV",
        "colab_type": "code",
        "outputId": "74fac090-ae5c-467e-ae91-406189514121",
        "executionInfo": {
          "status": "ok",
          "timestamp": 1579569930094,
          "user_tz": 480,
          "elapsed": 369,
          "user": {
            "displayName": "Preethi Lahoti",
            "photoUrl": "",
            "userId": "13345756409883217889"
          }
        },
        "colab": {
          "height": 85
        }
      },
      "source": [
        "print('Female group-size in synthetic data: {}'.format(len(train_df[(train_df.sex=='Female')])/len(train_df)))\n",
        "print('Male group-size in synthetic data: {}'.format(len(train_df[(train_df.sex!='Female')])/len(train_df)))\n",
        "print('Female base-rate in original train-data: {}'.format(len(train_df[(train_df.sex=='Female') & (train_df.income == '>50K')])/len(train_df[(train_df.sex=='Female')])))\n",
        "print('Male base-rate in original data: {}'.format(len(train_df[(train_df.sex!='Female') & (train_df.income == '>50K')])/len(train_df[(train_df.sex!='Female')])))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Female group-size in synthetic data: 0.33079450876815825\n",
            "Male group-size in synthetic data: 0.6692054912318418\n",
            "Female base-rate in original train-data: 0.10946058861758426\n",
            "Male base-rate in original data: 0.3057365764111978\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8XNpjHdAokl3",
        "colab_type": "code",
        "outputId": "107ee91e-0962-45fd-dcae-ed169a9be40b",
        "executionInfo": {
          "status": "ok",
          "timestamp": 1579569931236,
          "user_tz": 480,
          "elapsed": 567,
          "user": {
            "displayName": "Preethi Lahoti",
            "photoUrl": "",
            "userId": "13345756409883217889"
          }
        },
        "colab": {
          "height": 218
        }
      },
      "source": [
        "sns.catplot(data=train_df,x='income',hue='sex',kind='count',size=3)\n",
        "plt.show()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAASQAAADJCAYAAACKVE8EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAH+lJREFUeJzt3XtUVFX/P/D3gNxvCjKgqFwNHjBR\nMFBRbiMSQkup9FFTREwuTngB74w1UN7SxzS8ZYlQovHQg8mDUV5AtKyBIC9oy8sT5F1Q1BagBMz+\n/eGP83UEdFCGOTif11pnxZy9Z8/es/K99jlzzj4CxhgDIYTwgJa6O0AIIS0okAghvEGBRAjhDQok\nQghvUCARQniDAokQwhsUSIQQ3qBAIoTwBgUSIYQ3KJAIIbxBgdQBAoFA3V0g5KVGgUQI4Q0KJEII\nb1AgEUJ4o0sDKScnByKRCGZmZq3Oxxw9ehQCgUBhGzJkiEKd2tpaREZGwtTUFBYWFkhMTERzc7NC\nnV27dsHe3h4GBgYICAjApUuXFMovXLgAf39/GBgYwN7eHunp6SoZKyGk47o0kOrr6xEYGIilS5e2\nW+fGjRvcduTIEYUysViMkpISHD58GNnZ2di7dy9WrlzJlRcUFCAmJgYSiQQlJSUQCoUIDQ1FU1MT\nAKCxsRGhoaGwsrJCSUkJJBIJoqOjUVRUpJoBE0I6hqlBYWEhe/Kj29r3uJqaGqatrc0KCgq4fTt3\n7mRCoZA1NzczxhgLDw9nERERXHltbS0zMDBg//3vfxljjO3fv58ZGBiw2tpars706dPZW2+9pVS/\n1fR1EaIxeqg5D1uxs7ODXC7HyJEj8fHHH2PAgAEAg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d/8+fOZvb0999rW\n1paNHz+ee93c3MxMTExYWFiYwr6ePXuy1NRUxhhjhYWFTE9Pj927d0+h7ZkzZyq0RUgLmiG9BP7x\nj39AT0+Pe21jY4Nbt25xr0tLSzF27Ng23/vXX3/h6tWr8PX1Vdjv5+eHyspK1NfXc/vc3d25v7W0\ntLg1sR/fJxQKucXVSkpK8Pfff8PGxkZhAbrdu3e3+wQRotloVfSXwJOP/REIBGBP/Fbx+IL5bXmy\n/Mn3A2j1RA+BQNDmvpZF/eVyOczMzFBSUvLMPhMC0DkkjeDp6YkffvihzTJTU1P069cPRUVFCvuP\nHTsGe3t7hccTddSwYcNw7949PHz4EE5OTgrbgAEDnrtd8vKiGZIGWLFiBUJCQjB//nxERUVBT08P\nP//8M0aMGAFnZ2csW7YMiYmJGDhwIPz9/VFQUIBt27Zhy5YtL/S5gYGBGDNmDN58802sXbsW7u7u\nuHv3Lk6cOAF9fX3Mnj27k0ZIXhYUSBpg7Nix+O677yCVSvHZZ59BV1cXHh4e3HmjuLg41NXVYdWq\nVZgzZw769++PNWvWYNasWS/0uQKBALm5uUhOTkZCQgKuXbsGc3NzDBkyBIsXL+6MoZGXDF0YSQjh\nDTqHRAjhDQokQghvUCARQniDAokQwhsUSIQQ3qBAIoTwBgUSIYQ3KJAIIbzx/wAGhSYGiuMWSAAA\nAABJRU5ErkJggg==\n",
            "text/plain": [
              "<Figure size 432.984x300 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9rbnk2RfqJMI",
        "colab_type": "text"
      },
      "source": [
        "#### Synthetic data distribution"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rYddZ57fo-cT",
        "colab_type": "code",
        "outputId": "6114958e-0e74-469f-e227-bafff5a54225",
        "executionInfo": {
          "status": "ok",
          "timestamp": 1579569932783,
          "user_tz": 480,
          "elapsed": 403,
          "user": {
            "displayName": "Preethi Lahoti",
            "photoUrl": "",
            "userId": "13345756409883217889"
          }
        },
        "colab": {
          "height": 34
        }
      },
      "source": [
        "column_types = ['sex:Female','income:>50K']\n",
        "percentages = [0.33,0.30]\n",
        "restrictions = create_restrictions(column_types,percentages)\n",
        "print('Sampling data with restrictions: {}'.format(restrictions))\n",
        "sampled_train_df = sample_data(train_df, restrictions=restrictions)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Sampling data with restrictions: [Restriction(column_name='sex', types=['Female'], percentages=[0.33]), Restriction(column_name='income', types=['>50K'], percentages=[0.3])]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MheqnB9yogzx",
        "colab_type": "code",
        "outputId": "0bcb2ae6-a721-4941-ce13-02f8b2ef0ab8",
        "executionInfo": {
          "status": "ok",
          "timestamp": 1579569933432,
          "user_tz": 480,
          "elapsed": 345,
          "user": {
            "displayName": "Preethi Lahoti",
            "photoUrl": "",
            "userId": "13345756409883217889"
          }
        },
        "colab": {
          "height": 85
        }
      },
      "source": [
        "print('Female group-size in synthetic data: {}'.format(len(sampled_train_df[(sampled_train_df.sex=='Female')])/len(sampled_train_df)))\n",
        "print('Male group-size in synthetic data: {}'.format(len(sampled_train_df[(sampled_train_df.sex!='Female')])/len(sampled_train_df)))\n",
        "print('Female base-rate in synthetic data: {}'.format(len(sampled_train_df[(sampled_train_df.sex=='Female') & (sampled_train_df.income == '>50K')])/len(sampled_train_df[(sampled_train_df.sex=='Female')])))\n",
        "print('Male base-rate in synthetic data: {}'.format(len(sampled_train_df[(sampled_train_df.sex!='Female') & (sampled_train_df.income == '>50K')])/len(sampled_train_df[(sampled_train_df.sex!='Female')])))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Female group-size in synthetic data: 0.32999600749362734\n",
            "Male group-size in synthetic data: 0.6700039925063727\n",
            "Female base-rate in synthetic data: 0.29995346672871104\n",
            "Male base-rate in synthetic data: 0.3092225889255592\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "outputId": "9b2a4fa8-e501-4754-f952-c8a4a6e71bdb",
        "executionInfo": {
          "status": "ok",
          "timestamp": 1579569938347,
          "user_tz": 480,
          "elapsed": 623,
          "user": {
            "displayName": "Preethi Lahoti",
            "photoUrl": "",
            "userId": "13345756409883217889"
          }
        },
        "id": "pcv_QZ8Onx8I",
        "colab": {
          "height": 218
        }
      },
      "source": [
        "# Group sizes remain the same, base-rate changes.\n",
        "sns.catplot(data=sampled_train_df,x='income',hue='sex',hue_order=['Male','Female'],order=['<=50K','>50K'],kind='count',size=3)\n",
        "plt.show()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAASQAAADJCAYAAACKVE8EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAH+RJREFUeJzt3XlUVHX/B/D3gOybgjOgqKwGD5gL\nEKgo24iE0FEqfdRcEJPFCRdwZ6yBXNPHNNyyRCjReOjB4sEoFxAtayDIBe24/ILEFRS1AygB8/39\n4eE+joAOyjAX+bzOuUfmfu985/PlyPt87527CBhjDIQQwgNami6AEEKaUSARQniDAokQwhsUSIQQ\n3qBAIoTwBgUSIYQ3KJAIIbxBgUQI4Q0KJEIIb1AgEUJ4gwKpHQQCgaZLIOSlRoFECOENCiRCCG9Q\nIBFCeKNTAykrKwtisRhmZmYtjsccO3YMAoFAaRk6dKjSNjU1NQgPD4epqSksLCwQHx+PpqYmpW32\n7NkDOzs7GBgYwN/fH5cvX1Zqv3jxIvz8/GBgYAA7OzukpqaqZayEkPbr1ECqq6tDQEAAli1b1uY2\nN27c4JajR48qtUkkEhQVFeHIkS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FRXjvvfcwb948nD9/HsCjoHvjjTdw+vRpZGRkoLS0FDExMZg8eTLdLoS0TnOX0ZHnNXPm\nTCYWi7mfe/furXRx6tq1a5mVlRX3etSoUSwkJKTN/vr168cWL16stG7BggXMzs6Oe21jY8PGjx/P\nvW5qamImJiYsNDRUaV3Pnj1ZcnIyY4yx/Px8pqenx+7du6fU96xZs5T6IqQZzZBeAv/4xz+gp6fH\nvba2tsatW7e418XFxRg7dmyr7/3rr79w9epV+Pj4KK339fVFeXk56urquHVDhgzhftbS0uLuif34\nOpFIxN1craioCH///Tesra2VbkC3d+/eNp8gQro3uiv6S+DJx/4IBAKwJ76rePyG+a15sv3J9wNo\n8UQPgUDQ6rrmm/orFAqYmZmhqKjomTUTAtAxpG7B3d0dP/zwQ6ttpqam6NevHwoKCpTWHz9+HHZ2\ndkqPJ2ovDw8P3Lt3Dw8fPoSjo6PSMmDAgOful7y8aIbUDaxcuRLBwcFYsGABIiIioKenh59//hkj\nRoyAk5MTli9fjvj4eAwcOBB+fn7Iy8vDjh07sG3bthf63ICAAIwZMwZvvvkm1q9fjyFDhuDu3bs4\nefIk9PX1MWfOnA4aIXlZUCB1A2PHjsV3330HmUyGTz/9FLq6unBzc+OOG8XExKC2thZr1qzB3Llz\n0b9/f6xbtw6zZ89+oc8VCATIzs5GYmIi4uLicO3aNZibm2Po0KFYsmRJRwyNvGToxEhCCG/QMSRC\nCG9QIBFCeIMCiRDCGxRIhBDeoEAihPAGBRIhhDcokAghvEGBRAjhjf8HfxQuPFWSGUUAAAAASUVO\nRK5CYII=\n",
            "text/plain": [
              "<Figure size 432.984x300 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-4bKIvkMmwKL",
        "colab_type": "text"
      },
      "source": [
        "## Sample data with specified label-noise"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "T0PdZDo45W9J",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "fractions = [0.1, 0.2, 0.3, 0.4, 0.5]\n",
        "for frac in fractions:\n",
        "  for version in np.arange(10):\n",
        "    sampled_train_df = sample_data_and_flip_class_label(train_df, frac=frac, flip_dict={'<=50K':'>50K','>50K':'<=50K'})\n",
        "    output_file_path = os.path.join(dataset_base_dir,'income_flip_labels{}_version{}_train.csv'.format(frac,version)\n",
        "    with open(output_file_path, mode=\"w\") as output_file:\n",
        "        sampled_train_df.to_csv(output_file,index=False,columns=feature_names,header=False)\n",
        "        output_file.close()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "AICIIZkgmmwY",
        "colab_type": "text"
      },
      "source": [
        "## Sample data with specified group-sizes"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "K_lpbfUM5ZHq",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "column_types = ['sex:Female']\n",
        "_percentages =  [[0.1],[0.2],[0.3],[0.4],[0.5],[0.6],[0.7],[0.8],[0.9]]\n",
        "for percentages in _percentages:\n",
        "  for version in np.arange(10):\n",
        "    restrictions = create_restrictions(column_types,percentages)\n",
        "    sampled_train_df = sample_data(train_df, restrictions=restrictions)\n",
        "\n",
        "    output_file_path = os.path.join(dataset_base_dir,'female_groupsize{}_version{}_train.csv'.format(percentages[0],version)\n",
        "    with open(output_file_path, mode=\"w\") as output_file:\n",
        "        sampled_train_df.to_csv(output_file,index=False,columns=feature_names,header=False)\n",
        "        output_file.close()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Dj7g4Uj75gRY",
        "colab_type": "text"
      },
      "source": [
        "## Sample data with specified base-rates"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "PNFiR4Ge5bZn",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "column_types = ['sex:Female','income:>50K']\n",
        "_percentages =  [[0.33,0.1],[0.33,0.2],[0.33,0.3],[0.33,0.4],[0.33,0.5],[0.33,0.6],[0.33,0.7],[0.33,0.8],[0.33,0.9]]\n",
        "for percentages in _percentages:\n",
        "  for version in np.arange(10):\n",
        "    restrictions = create_restrictions(column_types,percentages)\n",
        "    sampled_train_df = sample_data(train_df, restrictions=restrictions)\n",
        "\n",
        "    output_file_path = os.path.join(dataset_base_dir,'female_baserate{}_version{}_train.csv'.format(percentages[1],version)\n",
        "    with open(output_file_path, mode=\"w\") as output_file:\n",
        "        sampled_train_df.to_csv(output_file,index=False,columns=feature_names,header=False)\n",
        "        output_file.close()"
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}